const { app, Routers } = require('./src/app')
const { routes, port } = require('./setting')
const express = require('express')
const chalk = require('chalk')
const cors = require('cors')
const createError = require('http-errors');

app.use(cors())
app.use(express.json())
app.use(express.urlencoded({ extend: false }))

app.use(express.static('server'))

Routers(routes, false)

app.use(function(req, res, next) {
    next(createError(404));
});

app.use(function (err, req, res, next) {
    const response = {
        code: 500,
        msg: '报错信息'
    }
    if (err) {
        response.msg = err.message
    }
    res.status(500).json(response)
})

app.listen(port, () => {
    console.log(chalk.green('node.js服务器已经启动，端口' + port))
})
